package cn.school.web;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.school.mybatis.pojo.Grade;
import cn.school.mybatis.service.GradeService;

/**
 * Servlet implementation class GradeServlet
 */
@WebServlet("/GradeServlet")
public class GradeServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public GradeServlet() {
		super();
		// TODO Auto-generated constructor stub
	}

	GradeService gservie = new GradeService();

	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// 显示全部的年级,用table显示
		List<Grade> list = gservie.select();
		request.setAttribute("grades", list);
		request.getRequestDispatcher("/page2/grade.jsp").forward(request, response);
//		response.setContentType("text/html;charset=utf-8");
//		PrintWriter out = response.getWriter();
//		out.print("<!DOCTYPE html>");
//		out.print("<html>");
//		out.print("<body>");
//		out.print("<table border='1' cellspacing='0' cellpading='0'>");
//		out.print("<tr><td>编号</td><td>年级名</td></tr>");
//		for (Grade g : list) {
//			out.print("<tr><td>" + g.getId() + "</td><td>" + g.getGname() + "</td></tr>");
//		}
//		out.print("</table>");
//		out.print("</body>");
//		out.print("</html>");
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}

}
